package com.zzptc.lhl.myapplication;

import androidx.appcompat.app.AppCompatActivity;

import android.os.Bundle;
import android.util.Log;

import com.google.gson.Gson;
import com.zzptc.lhl.myapplication.entity.Students;

public class Main2Activity extends AppCompatActivity {
    private static final String TAG = "Main2Activity";
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main2);
        Gson gson=new Gson();
        //language=JSON
        String str = "{\n" +
                "  \"code\": 1,\n" +
                "  \"data\": [{\n" +
                "    \"stu_id\": 1,\n" +
                "    \"stu_name\": \"张三\",\n" +
                "    \"stu_age\": \"20\"\n" +
                "  },{\"stu_id\": 2,\n" +
                "    \"stu_name\": \"李四\",\n" +
                "    \"stu_age\": \"20\"}]\n" +
                "}";
        Students students=gson.fromJson(str,Students.class);
        Log.d(TAG, "onCreate: "+students.getData().get(1).getStu_name());
        Log.d(TAG, "onCreate: "+gson.toJson(students));
    }
}
